package com.alks.function.mapper.procurement;


import com.alks.entity.data.entity.*;
import com.alks.function.data.dto.procurement.*;
import com.alks.function.data.request.procurement.LotNoRequest5;
import com.alks.function.data.request.procurement.LotNoRequest6;
import com.alks.function.data.request.procurement.SummaryRequest;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.annotations.Param;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.List;

@Mapper
public interface SummaryOperationMapper {
    /**
     * 待汇总指令
     * @return
     */
    List<SummaryALLDataDto> getNotSummaryLotNoList(@Param("companyId") String companyId, @Param("request") SummaryRequest request);

    /*先把要重新汇总的数据查出基础信息*/
    List<SummaryALLDataDto> getNotSummaryLotNoList2(String companyId ,String lotNo);

    /**
     * 汇总号查询
     * @param companyId
     * @return
     */
    List<SummaryDataDto> getSummaryNumberList(@Param("companyId") String companyId, @Param("request") SummaryRequest request);

    /**
     * 汇总指令查询
     * @param companyId
     * @return
     */
    SummaryDataDto1 getSummaryLotNoList(@Param("companyId") String companyId, @Param("request") SummaryRequest request);

    /**
     * 汇总材料查询
     * @return
     */
    List<SummaryDataDto2> getSummaryMaterialList(@Param("companyId") String companyId, @Param("request") SummaryRequest request);

    /**
     * 汇总指令材料明细查询
     * @return
     */
    List<SummaryDataDto3> getSummaryDetailList(@Param("companyId") String companyId, @Param("request") SummaryRequest request);

    /**
     * 贴合子材料查询
     * @param companyId
     * @return
     */
    List<SummaryDataDto4> getBondingSubmaterial(@Param("companyId") String companyId, @Param("request") SummaryRequest request);

    /**
     * 删除指令资料查询
     * @param companyId
     * @return
     */
    @Select("select LOT_NO from PC_SUM_LOT_TEMP where COMPANY_ID = #{companyId} order by LOT_NO ASC")
    List<String> getDeleteLotNoList(String companyId);

    /**
     * 删除指令资料查询：恢复指令
     * @param companyId
     * @param lotNo
     */
    @Delete("delete from PC_SUM_LOT_TEMP where COMPANY_ID = #{companyId} and LOT_NO = #{lotNo}")
    int recoverLotNo(@Param("companyId") String companyId, @Param("lotNo") String lotNo);

    /**
     * 不汇总指令删除
     * @param companyId
     * @param lotNo
     */
    @Insert("INSERT INTO PC_SUM_LOT_TEMP (COMPANY_ID,LOT_NO) values (#{companyId},#{lotNo})")
    int deleteNotSummaryLotNo(@Param("companyId") String companyId, @Param("lotNo") String lotNo);

    @Select("SELECT COALESCE(COUNT(*), 0) FROM PC_SUM_LOT_TEMP WHERE COMPANY_ID = #{companyId} and LOT_NO = #{lotNo}")
    int getDeleteLotNo(@Param("companyId") String companyId, @Param("lotNo") String lotNo);

    @Select("SELECT * from PC040 where COMPANY_ID = #{companyId} and SUM_NO = #{sumNo}")
    Pc040 getSummaryNumberBySumNo(@Param("companyId") String companyId, @Param("sumNo") String sumNo);

    @Select("SELECT * from PC041 where COMPANY_ID = #{companyId} and SUM_NO = #{sumNo}")
    Pc041 getSummaryLotNoBySumNo(@Param("companyId") String companyId, @Param("sumNo") String sumNo);

    @Select("SELECT * from PC042 where COMPANY_ID = #{companyId} and SUM_NO = #{sumNo}")
    List<Pc042> getSummaryMaterialBySumNo(@Param("companyId") String companyId, @Param("sumNo") String sumNo);

    @Select("SELECT * from PC043 where COMPANY_ID = #{companyId} and SUM_NO = #{sumNo} ")
    List<Pc043> getSummaryDetailListBySumNo(@Param("companyId") String companyId, @Param("sumNo") String sumNo);

    @Select("SELECT * from PC044 where COMPANY_ID = #{companyId} and SUM_NO = #{sumNo} ")
    List<Pc044> getBondingSubmaterialBySumNo(@Param("companyId") String companyId, @Param("sumNo") String sumNo);

    @Delete("delete from PC040 where COMPANY_ID = #{pc040.companyId} and SUM_NO = #{pc040.sumNo}")
    int deletePc040(@Param("pc040") Pc040 pc040);

    @Delete("delete from PC041 where COMPANY_ID = #{pc041.companyId} and SUM_NO = #{pc041.sumNo}")
    int deletePc041(@Param("pc041") Pc041 pc041);

    int deletePc042(List<Pc042> list2);

    int deletePc043(List<Pc043> pc043);

    int deletePc044(List<Pc044> pc044);


    void getBatchProcess(@Param("pc042") Pc042 pc042, @Param("mtoList") List<String> mtoList);


    /**
     * 材料请购：批处理
     */
    int pc042Update(@Param("request") List<LotNoRequest5> request, @Param("userName") String userName, @Param("now") LocalDate now, @Param("loginName") String loginName);

    /**
     * 导出汇总材料明细
     * @param companyId
     * @param sumNo
     * @return
     */
    List<ExportSummaryDataDto> queryExportSummaryMaterialDetail(@Param("companyId") String companyId, @Param("sumNoList") List<String> sumNo);

    /*添加PC040*/
    int addPc040(Pc040 pc040);

    /*添加PC041*/
    int addPc041(Pc041 pc041);

    /*批量添加PC042*/
    int addPc042(@Param("pc042List") List<Pc042> pc042List);

    /*批量添加PC0432*/
    int addPc043(@Param("pc043List") List<Pc043> pc043List);

    /*批量添加PC0434*/
    int addPc044(@Param("pc044List") List<Pc044> pc044List);

    /*先查询当时最大汇总号*/
    SummaryDataDto getMaxSummary(@Param("companyId") String companyId);

    /*更新回原先的汇总数据*/
    int pc042UpdateBack(LotNoRequest6 request);

    /*批量更新回原先的汇总数据*/
    int pc042UpdateBackBatch(List<LotNoRequest6> list, String companyId);

    /*1.查询PC_LOT_USAGE中有没有错误数据*/
    List<CleanDataDto> cleanPcLotUsage(String companyId, String lotNo);

    /*2.批量查询PC_LOT_USAGE中有没有错误编码*/
    List<CleanDataDto> cleanPcLotUsageBatch(String companyId, List<String> list);

    List<CleanDataDto> cleanPcLotUsageNoColor(String companyId, String lotNo);

    /*查询SD_BOM_FIT_SUB中有颜色有没有错误数据*/
    List<CleanDataDto> cleanSdBomFitSub(String companyId, String lotNo);

    /*1.查询 PC_LOT_USAGE_FIT 错误编码*/
    List<CleanDataDto> cleanPcLotUsageFit(String companyId, String lotNo);

    /*2.批量查询 PC_LOT_USAGE_FIT 错误编码*/
    List<CleanDataDto> cleanPcLotUsageFitBatch(String companyId, List<String> list);

    /*1.查询SD_BOM_FIT_SUB中有没有错误数据（不根据指令根据材料）*/
    List<CleanDataDto> cleanSdBomFitSub2();

    /*2.批量根据指令查询SD_BOM_FIT_SUB中有没有错误数据*/
    List<CleanDataDto> cleanSdBomFitSubBatch(String companyId, List<String> list);

    List<CleanDataDto> cleanSdBomFitSubNoColor(String companyId, String lotNo);

    /*查询YF_BOM_FIT_SUB中有没有错误数据*/
    List<CleanDataDto> cleanYFBomFitSub2();

    /*查询PC_LOT_USAGE_FIT_CHG中有没有错误数据*/
    List<CleanDataDto> getErrorPcLotUsageFitChg(String lotNo);

    /*查询MP_PUR_DIS中有没有错误数据*/
    List<CleanDataDto> getErrorMpPurDis(String lotNo);

    /*查询PC_LOT_USAGE_CHG中有没有错误数据*/
    List<CleanDataDto> getErrorPcLotUsageChg(String lotNo);


    /*采购汇总作业：数据平移*/
    List<SummaryMaterialsDto> summaryDataExchange2(@Param("companyId") String companyId, @Param("request") SummaryRequest request);

    /*更新为已经订购*/
    int updatePc042Two(Pc042 date2);

    /*添加数据*/
    int addPc042Two(Pc042 date);

    int updatePc042Two2(Pc042 date2);

    void updatePc040Two(String companyId, String lotNo);

    Pc040 getPc040Two(String companyId, String lotNo);

    List<SummaryMaterialsDto> summaryDataExchange3(String companyId, SummaryRequest request);


}
